/** 设置各Emu平台的名字,以及相关快捷键的类,是一个静态类

  By setycyas @2024-11-27
*/

class MyEmu {

  /* 各个Emu平台的名字,常量
  */
  static WINKAWAKS := "winkawaks.exe"
  static XZONE := "x-zone.exe"
  static NEBULA := "nebula.exe"
  static NEBULA_SP2_CPS := "nebula2.25sp2-cps.exe" ;三国战纪专用
  static FBAS := "fbas.exe" ; 对应三国战记和西游释厄传等专用改装的模拟器
  static FBASX64 := "fbas-x64.exe" ;
  static MAME := "mame.exe" ;
  static FBNEO64 := "fbneo64.exe"
  static EMU_LIST := [MyEmu.WINKAWAKS, MyEmu.XZONE, MyEmu.NEBULA,
    MyEmu.FBAS, MyEmu.FBASX64, MyEmu.MAME, MyEmu.FBNEO64, MyEmu.NEBULA_SP2_CPS] ;模拟器列表

  /* 设置各平台的热键的函数,exeName应该是上面各Emu平台的名字之一
  */
  static setupHotkeys(exeName){

    switch (exeName)
    {
      case this.WINKAWAKS:
      {
        HotIfWinActive("ahk_exe " . exeName)
        Hotkey("del", this._winkawaks_stateSave.bind(this))
        Hotkey("pgdn", this._winkawaks_stateLoad.bind(this))
        Hotkey("home", this._winkawaks_previousState.bind(this))
        Hotkey("pgup", this._winkawaks_nextState.bind(this))
        Hotkey("numpad0", this._winkawaks_pause.bind(this))
        HotIfWinActive()
      }
      case this.FBNEO64:
      {
        HotIfWinActive("ahk_exe " . exeName)
        Hotkey("end", this._fbneo64_stateSave.bind(this))
        Hotkey("pgdn", this._fbneo64_stateLoad.bind(this))
        Hotkey("home", this._fbneo64_previousState.bind(this))
        Hotkey("pgup", this._fbneo64_nextState.bind(this))
        Hotkey("numpad0", this._fbneo64_pause.bind(this))
        HotIfWinActive()
      }
      case this.NEBULA:
      {
        HotIfWinActive("ahk_exe " . exeName)
        Hotkey("del", this._nebula_stateSave.bind(this))
        Hotkey("pgdn", this._nebula_stateLoad.bind(this))
        Hotkey("numpad0", this._nebula_pause.bind(this))
        HotIfWinActive()
      }
      case this.NEBULA_SP2_CPS:
      {
        HotIfWinActive("ahk_exe " . exeName)
        Hotkey("del", this._nebula_stateSave.bind(this))
        Hotkey("pgdn", this._nebula_stateLoad.bind(this))
        Hotkey("numpad0", this._nebula_pause.bind(this))
        HotIfWinActive()
      }
      case this.XZONE:
      {
        HotIfWinActive("ahk_exe " . exeName)
        Hotkey("numpad2", this._xzone_suspend.bind(this), "S") ;不会中断
        ;Hotkey("space", this._xzone_space.bind(this))
        ;Hotkey("numpad0", this._xzone_pause.bind(this))
        HotIfWinActive()
      }
    }

  }

  /* winkawaks.exe的热键函数
  */
  static _winkawaks_stateSave(key){
    send("{F5 down}{F5 up}")
  }
  static _winkawaks_stateLoad(key){
    send("{F7 down}{F7 up}")
  }
  static _winkawaks_nextState(key){
    send("{F8 down}{F8 up}")
  }
  static _winkawaks_previousState(key){
    send("{F6 down}{F6 up}")
  }
  static _winkawaks_pause(key){
    send("{enter down}{enter up}")
  }

  /* nebula.exe的热键函数
  */
  static _nebula_stateSave(key){
    send("{F10 down}")
    sleep(50)
    send("{F10 up}")
  }
  static _nebula_stateLoad(key){
    send("{F11 down}")
    sleep(50)
    send("{F11 up}")
  }
  static _nebula_pause(key){
    send("{pause down}")
    sleep(50)
    send("{pause up}")
  }

  /* x-zone.exe的热键函数
  */
  static _xzone_suspend(key){ ;热键状态切换
    Suspend()
  }
  static _xzone_space(key){ ;空格键作用,替换成p键
    send("{p down}")
    sleep(50)
    send("{p up}")
  }
  static _xzone_pause(key){ ;暂停
    send("{~ down}")
    sleep(50)
    send("{~ up}")
  }
  
  /* fba64.exe的热键函数 
  */
  static _fba64_pause(key){
    send("{pause down}{pause up}")
  }
  static _fba64_stateSave(key){ ;即时存档当前state
    send("{F10 down}{F10 up}")
  }
  static _fba64_stateLoad(key){ ;即时读档当前state
    send("{F9 down}{F9 up}")
  }
  static _fba64_nextState(key){ ;从文件中读取即时存档
    send("{F11 down}{F11 up}")
  }
  static _fba64_previousState(key){ ;即时存档到文件
    send("{F8 down}{F8 up}")
  }
  
  /* fbneo64.exe的热键函数 
  */
  static _fbneo64_pause(key){
    send("{pause down}{pause up}")
  }
  static _fbneo64_stateSave(key){ ;即时存档当前state
    send("{F10 down}{F10 up}")
  }
  static _fbneo64_stateLoad(key){ ;即时读档当前state
    send("{F9 down}{F9 up}")
  }
  static _fbneo64_nextState(key){ ;从文件中读取即时存档
    send("{F11 down}{F11 up}")
  }
  static _fbneo64_previousState(key){ ;即时存档到文件
    send("{F8 down}{F8 up}")
  }
  
}

/* 单纯使用模拟器快捷键
*/ if (A_ScriptName == "MyEmu.2.ahk") {
  SendMode("Event")
  MyEmu.setupHotkeys(MyEmu.FBA64)
}